package work.mediway.mdm.core.page;

import com.fasterxml.jackson.annotation.JsonIgnore;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/1/1
 */
@ToString
@ApiModel(value = "分页参数")
public class QueryRequest {

    public static final Integer DEFAULT_PAGE = 1;

    public static final Integer DEFAULT_PAGE_SIZE = 1000;

    @ApiModelProperty(value = "页码", allowableValues = "1,2,3,4,5")
    @Setter
    private Integer current;

    @ApiModelProperty(value = "页大小", allowableValues = "10,20,30,40,50")
    @Setter
    private Integer size;


    /**
     * 排序字段
     */
    @ApiModelProperty(value = "排序字段", hidden = true)
    @Setter
    @Getter
    @JsonIgnore
    private String field;


    /**
     * 排序规则，asc升序，desc降序
     */
    @ApiModelProperty(value = "排序规则", hidden = true)
    @Setter
    @Getter
    @JsonIgnore
    private String order;

    public Integer getCurrent() {
        if (ObjectUtil.isEmpty(current) || current < 1) {
            current = DEFAULT_PAGE;
        }
        return current;
    }

    public Integer getSize() {
        if (ObjectUtil.isEmpty(size) || size < 1) {
            size = DEFAULT_PAGE_SIZE;
        }
        return size;
    }

    public QueryRequest() {
    }

    public QueryRequest(Integer current, Integer size) {
        this.current = current;
        this.size = size;
    }
}
